const express = require('express');
const router = express.Router();
const bannerCtrl = require('../controller/banner')
const uploadCtrl = require('../controller/upload')
const bannerValidator = require('../validator/banner')

// 获取轮播图
router.get('/banners', bannerCtrl.getBanner);

// 添加轮播图
router.post('/banners', (req, res, next) => {
  req.params.type = 'banner'
  next()
}, uploadCtrl.upload, uploadCtrl.uploadType(true), bannerCtrl.addBanner);

// 删除轮播图

router.delete('/banners/:id', bannerValidator.checkBannerId, bannerCtrl.delBanner);


//修改轮播图

router.put('/banners/:id', bannerValidator.checkBannerId, (req, res, next) => {
  req.params.type = 'banner'
  next()
}, uploadCtrl.upload, uploadCtrl.uploadType(true), bannerCtrl.updateBanner);

//改变启用状态
router.post('/banners/isuse', bannerValidator.is_useBanner, bannerCtrl.is_useBanner);

// 前台页面获取轮播图
router.get('/indexbanners', bannerCtrl.indexBanners);

module.exports = router;



